package com.caishi.lkx.common;

import cn.hutool.core.util.ObjectUtil;
import com.caishi.lkx.common.context.Context;
import com.zzw.common.annotation.ApiResult;
import com.zzw.common.annotation.ApiTimeRecord;
import com.zzw.common.mysql.MybatisPlusEnum;
import com.caishi.lkx.common.context.UserContext;

import javax.annotation.Resource;
import java.util.LinkedHashSet;
import java.util.Map;

/**
 * @author by keray
 * date:2019/8/1 10:08
 */
@ApiResult
@ApiTimeRecord(gt = 2000)
public class BaseApi {

    @Resource
    protected UserContext userContext;

    @Resource(name = "customContext")
    protected Context context;

    protected Map<String, Object> clearReturnEmptyStr(Map<String, Object> param) {
        for (String key : new LinkedHashSet<>(param.keySet())) {
            Object value = param.get(key);
            if (ObjectUtil.isEmpty(value)) {
                param.remove(key);
            }
            if (value instanceof MybatisPlusEnum mp) {
                param.put(key, mp.getCode());
            }
        }
        return param;
    }

}
